//
//  HUDManager.m
//  AppKit
//
//  Created by tenltrs on 2018/10/18.
//  Copyright © 2018年 Tenltrs. All rights reserved.
//

#import "HUDManager.h"

#import <KkmhSwift-Swift.h>

@implementation HUDManager

+(id)loadShowing{
    [self loadHideing];
    return [self loadShowingToView:[self getView]];
}

+(id)loadShowingToView:(UIView *)view{
    
    [self loadHideingFromView:view];
    MBProgressHUD * mdHud= [MBProgressHUD showHUDAddedTo:view animated:YES];
    mdHud.contentColor=[UIColor whiteColor];
    mdHud.removeFromSuperViewOnHide = YES;
    mdHud.bezelView.backgroundColor=[UIColor colorWithRed:0 green:0 blue:0 alpha:0.7];
    mdHud.margin=15;
    [mdHud showAnimated:YES];
    return mdHud;
}


/**
 隐藏视图
 */
+(void)loadHideing{
    [self loadHideingFromView:[self getView]];
}

/**
 隐藏视图
 */
+(void)loadHideingFromView:(UIView *)view{
    [MBProgressHUD hideHUDForView:view animated:YES];
}

/**
 隐藏视图
 */
+(void)loadHideingAfter:(NSTimeInterval)delay{
    [self loadHideingFromView:[self getView] After:delay];
}

/**
 隐藏视图
 */
+(void)loadHideingFromView:(UIView *)view After:(NSTimeInterval)delay{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [MBProgressHUD hideHUDForView:view animated:YES];
    });
}


/**
 仅提示
 
 @param str 提示内容
 */
+(void)loadTextMessage:(NSString *)str{
    [self loadTextMessage:str ToView:[self getView]];
}

/**
 仅提示
 
 @param str 提示内容
 */
+(void)loadTextMessage:(NSString *)str ToView:(UIView *)view{
    
    [self loadHideingFromView:view];
    MBProgressHUD *HUD=[MBProgressHUD showHUDAddedTo:view animated:YES];
    HUD.contentColor=[UIColor whiteColor];
    HUD.bezelView.color=[[UIColor blackColor] colorWithAlphaComponent:0.7];
    HUD.mode=MBProgressHUDModeText;
    HUD.label.text=str;
    HUD.removeFromSuperViewOnHide=YES;
    HUD.margin=15;
    [HUD showAnimated:YES];
    [HUD hideAnimated:YES afterDelay:1.5];
}

/**
 成功提示
 
 @param str 提示内容
 */
+ (void)loadsuccessMessage:(NSString *)str{
    [self loadsuccessMessage:str ToView:[self getView]];
}

/**
 成功提示
 
 @param str 提示内容
 */
+ (void)loadsuccessMessage:(NSString *)str ToView:(UIView *)view{
    
    [self loadHideingFromView:view];
    MBProgressHUD *HUD=[MBProgressHUD showHUDAddedTo:view animated:YES];
    HUD.contentColor=[UIColor whiteColor];
    HUD.bezelView.color=[[UIColor blackColor] colorWithAlphaComponent:0.7];
    HUD.mode=MBProgressHUDModeCustomView;
    UIImageView * iconView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"HUDResources.bundle/hud_success"]];
    HUD.customView=iconView;
    HUD.label.text=str;
    HUD.removeFromSuperViewOnHide=YES;
    HUD.margin=15;
    [HUD showAnimated:YES];
    [HUD hideAnimated:YES afterDelay:1.5];
}

/**
 错误提示
 
 @param str 提示内容
 */
+ (void)loaderrorMessage:(NSString *)str{
    
    [self loaderrorMessage:str ToView:[self getView]];
}

/**
 错误提示
 
 @param str 提示内容
 */
+ (void)loaderrorMessage:(NSString *)str ToView:(UIView *)view{
    [self loadHideing];
    MBProgressHUD *HUD=[MBProgressHUD showHUDAddedTo:view animated:YES];
    HUD.contentColor=[UIColor whiteColor];
    HUD.bezelView.color=[[UIColor blackColor] colorWithAlphaComponent:0.7];
    HUD.mode=MBProgressHUDModeCustomView;
    UIImageView * iconView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"HUDResources.bundle/hud_error"]];
    HUD.customView=iconView;
    HUD.label.text=str;
    HUD.removeFromSuperViewOnHide=YES;
    HUD.margin=15;
    [HUD showAnimated:YES];
    [HUD hideAnimated:YES afterDelay:1.5];
}

+(UIView *)getView
{
    UIViewController * vc = [[NSCacheTool defaultCache] valueForKey:@"Current_Controller"];
    return vc.view;
}

@end
